﻿using Dal;
using Model;

namespace Bll
{
    public class storeBll
    {
        private readonly storeDal dal;

        public storeBll(storeDal dal)
        {
            this.dal = dal;
        }

        /// <summary>
        /// 门店增加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int PostAddStore(T_StoreInfo info)
        {
            try
            {
                int res = dal.GetSearchName(info.Sname);
                if(res > 0)
                {
                    return -1;
                }
                else
                {
                    int list = dal.PostAddStore(info);
                    if(list > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
               
            }
            catch (Exception)
            {
                throw;
            }
        }


        /// <summary>
        /// 显示数据查询
        /// </summary>
        /// <param name="name">门店名称</param>
        /// <param name="phone">门店电话</param>
        /// <param name="indexs">总页数</param>
        /// <param name="counts">总条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示几条</param>
        /// <returns></returns>
        public List<T_StoreInfo> GetStoreList(string? name, string? phone, out int indexs, out int counts, int pageIndex = 1, int pageSize = 2)
        {
            try
            {
                return dal.GetStoreList(name, phone, out indexs, out counts, pageIndex, pageSize);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetDeleteInfo(int id)
        {
            try
            {
                return dal.GetDeleteInfo(id);
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 优惠券添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int PostDiscountAdd(T_Discount info)
        {
            try
            {
                int res = dal.SearchName(info.Dname);
                if(res > 0)
                {
                    return -1;
                }
                else
                {
                    int list = dal.PostDiscountAdd(info);
                    if(list > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}